﻿using codeparser.net.v2.Contracts;

using System;
using System.Diagnostics.CodeAnalysis;
using System.Xml;

namespace codeparser.net.v2.Entities
{
    /// <summary>
    /// Represents a tag attribute.
    /// </summary>
    [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
    public class TagAttribute : IXmlWriter
    {
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the attribute style.
        /// </summary>
        /// <value>The attribute style.</value>
        public AttributeStyles Style
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the attribute value style.
        /// </summary>
        /// <value>The attribute value style.</value>
        public AttributeValueStyles ValueStyle
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public string Value
        {
            get;
            set;
        }

        /// <summary>
        /// Initializes a new instance of the TagAttribute type.
        /// </summary>
        /// <param name="name">The name.</param>
        public TagAttribute(string name)
            : this(name, AttributeStyles.Required)
        {
        }

        /// <summary>
        /// Initializes a new instance of the TagAttribute type.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="style">The attribute style.</param>
        public TagAttribute(string name, AttributeStyles style)
            : this(name, style, AttributeValueStyles.Required)
        {
        }

        /// <summary>
        /// Initializes a new instance of the TagAttribute type.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="style">The attribute style.</param>
        /// <param name="valueStyle">The attribute value style.</param>
        public TagAttribute(string name, AttributeStyles style, AttributeValueStyles valueStyle)
        {
            // Initialize the fields.
            this.Name = name;
            this.Style = style;
            this.ValueStyle = valueStyle;
        }

        /// <summary>
        /// Saves the tag attribute to the specified XML writer.
        /// </summary>
        /// <param name="writer">The XML writer.</param>
        void IXmlWriter.Save(XmlWriter writer)
        {
            // Write the attribute.
            writer.WriteStartElement("Attribute");
            {
                writer.WriteAttributeString("Name", this.Name);
                writer.WriteAttributeString("Style", this.Style.ToString());
                writer.WriteAttributeString("ValueStyle", this.ValueStyle.ToString());
            }
            writer.WriteEndElement();
        }
    }
}